package com.exam.controller;

import com.exam.pojo.ExamMessage;
import com.exam.service.ExamMessageService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ExamMessageController {
    @Resource
    private ExamMessageService examMessageService;

    @GetMapping("/exams/{id}/{pageNum}/{pageSize}")
    public PageInfo<ExamMessage> findStuExamPage(
            @PathVariable("id") Integer studentId,
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize){
        return examMessageService.queryPageByStuId(studentId, pageNum, pageSize);
    }
    @GetMapping("/exams/{id}")
    public List<ExamMessage> findMyExam(@PathVariable("id") Integer studentId){
        return examMessageService.queryByStuId(studentId);
    }
    @GetMapping("/exam/{id}")
    public ExamMessage findExamById(@PathVariable("id") Integer id){
        return examMessageService.queryById(id);
    }

    @GetMapping("/manage/exams/{id}/{pageNum}/{pageSize}")
    public PageInfo<ExamMessage> findTeaExamPage(
            @PathVariable("id") Integer teacherId,
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize){
        return examMessageService.queryPageByTeaId(teacherId,pageNum,pageSize);
    }

    @GetMapping("/manage/exams/{pageNum}/{pageSize}")
    public PageInfo<ExamMessage> findAllExamPage(
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize){
        return examMessageService.queryPageAll(pageNum,pageSize);
    }
    @PutMapping("/manage/exam/update")
    public int updateById(@RequestBody ExamMessage examMessage){
        return examMessageService.updateById(examMessage);
    }
    @DeleteMapping("/manage/exam/delete/{id}")
    public int deleteById(@PathVariable("id") Integer id){
        return examMessageService.deleteById(id);
    }
    @PostMapping("/manage/exam/add")
    public int add(@RequestBody ExamMessage examMessage){
        return examMessageService.add(examMessage);
    }
}
